package com.tanhua.admin.controller;



import com.tanhua.admin.service.SummaryService;
import com.tanhua.model.db.Summary;
import com.tanhua.model.vo.YearVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dashboard")
public class SummaryController {

    @Autowired
    private SummaryService summaryService;
    /**
     * 概要统计信息
     * GET   /summary
     * 参数:
     *      返回值:
     *             Summary对象
     */
    @GetMapping("/summary")
    public ResponseEntity<Summary> summary(){
        //调用service返回summary对象
        Summary summary = summaryService.sum();
        return ResponseEntity.ok(summary);
    }

    /**
     * Query:
     *      参数:sd开始时间 ed结束时间 type 101新增102活跃用户 103 次日留存率
     *      返回参数:
     *          thisYear[](本年):   title(String)日期   amount(integer)数量
     *          lastYear[](去年):  title(String)日期   amount(integer)数量
     *          GET     /dashboard/users
     */


    @RequestMapping("/users")
    public ResponseEntity queryAnalysisUsers(@RequestParam Long sd,
                                             @RequestParam Long ed,
                                             @RequestParam Integer type) {
        //String sdate = new SimpleDateFormat("yyyy-MM-dd").format(sd);
        //String edate = new SimpleDateFormat("yyyy-MM-dd").format(ed);
        YearVo yearVo = summaryService.users(sd, ed, type);
        System.out.println(yearVo);

        return ResponseEntity.ok(yearVo);
    }
}
